package views.components
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	[Embed(source="assets/assets.swf", symbol="CountDown")]
	public class CountDown extends MovieClip
	{
		private var timer:Timer = new Timer(1000);
		
		private var time:int = 3;
		
		public function CountDown()
		{
			super();
			
			this.stop();
			timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);
			timer.start();
		}
		
		private function onTimer(e:TimerEvent):void
		{
			time--;
			if(time == 0){
				dispatchEvent(new Event("CountEnd"));
				timer.stop();
				timer.removeEventListener(TimerEvent.TIMER, onTimer);
				this.parent.removeChild(this);
			}else{
				this.nextFrame();
			}
		}
	}
}